// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class REQUEST_SQM_S25 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("7 ARQ",7)]
  	    [HL7Field(HL7Version.v23, 7, HL7Repeat.False, HL7Required.True,"ARQ")]
	    public ARQ ARQ {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("9 APR",9)]
  	    [HL7Field(HL7Version.v23, 9, HL7Repeat.False, HL7Required.False,"APR")]
	    public APR APR {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("12 PID",12)]
  	    [HL7Field(HL7Version.v23, 12, HL7Repeat.False, HL7Required.False,"PID")]
	    public PID PID {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("14 RESOURCES",14)]
  	    [HL7Field(HL7Version.v23, 14, HL7Repeat.True, HL7Required.True,"RESOURCES_SQM_S25")]
	    public RESOURCES_SQM_S25[] RESOURCES {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("24 GENERAL_RESOURCE",24)]
  	    [HL7Field(HL7Version.v23, 24, HL7Repeat.False, HL7Required.False,"GENERAL_RESOURCE_SQM_S25")]
	    public GENERAL_RESOURCE_SQM_S25 GENERAL_RESOURCE {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			ARQ = PopSegmentParseAndCheckRequired<ARQ>(availableData, options, "ARQ");
			APR = PopSegmentParseAndCheckRequired<APR>(availableData, options, "APR");
			PID = PopSegmentParseAndCheckRequired<PID>(availableData, options, "PID");
			RESOURCES = ProcessGroupArray<RESOURCES_SQM_S25>(availableData, options, "RESOURCES");
			GENERAL_RESOURCE = ProcessGroup<GENERAL_RESOURCE_SQM_S25>(availableData, options, "GENERAL_RESOURCE");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isARQ = availableData.StartsWith("ARQ", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("ARQ", options.Version) || isARQ) {
				return isARQ;
			}
			bool isAPR = availableData.StartsWith("APR", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("APR", options.Version) || isAPR) {
				return isAPR;
			}
			bool isPID = availableData.StartsWith("PID", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PID", options.Version) || isPID) {
				return isPID;
			}
			RESOURCES_SQM_S25 testRESOURCES_SQM_S25 = new RESOURCES_SQM_S25();
			bool grpCCRESOURCES_SQM_S25 = (testRESOURCES_SQM_S25.CanConsume(availableData, options));
			if (IsRequired("RESOURCES", options.Version) || grpCCRESOURCES_SQM_S25) {
				return grpCCRESOURCES_SQM_S25;
			}
			GENERAL_RESOURCE_SQM_S25 testGENERAL_RESOURCE_SQM_S25 = new GENERAL_RESOURCE_SQM_S25();
			bool grpCCGENERAL_RESOURCE_SQM_S25 = (testGENERAL_RESOURCE_SQM_S25.CanConsume(availableData, options));
			if (IsRequired("GENERAL_RESOURCE", options.Version) || grpCCGENERAL_RESOURCE_SQM_S25) {
				return grpCCGENERAL_RESOURCE_SQM_S25;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "REQUEST";
			}
        }

        static REQUEST_SQM_S25() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(REQUEST_SQM_S25));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (ARQ != null) {
			string segmentValue = ARQ.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (APR != null) {
			string segmentValue = APR.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (PID != null) {
			string segmentValue = PID.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (RESOURCES != null && RESOURCES.Length > 0) {
			for (int i = 0; i < RESOURCES.Length; i++) {
				string segmentValue = RESOURCES[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (GENERAL_RESOURCE != null) {
			string segmentValue = GENERAL_RESOURCE.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

